<?php

declare(strict_types=1);

namespace App\Controller\Gift;

use App\Controller\BaseController;
use App\Model\Guild;
use App\Request\Gift\SendGiftRequest;
use App\Services\Gift\GiftService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;

class GiftController extends BaseController
{
    #[Inject]
    public GiftService $giftService;

    /**
     * Note - 礼物列表
     * DateTime 2024/8/19 16:24
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function list()
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $list = $this->giftService->list($userInfo, $params);
        return $this->return($list);

    }


    /**
     * Note - 送礼
     * DateTime 2024/8/19 16:23
     * User Admin
     * @param SendGiftRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function sendGift(SendGiftRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        // 1 安卓 2 IOS
        $params['from'] = intval($params['from'] ?? 1);
        $params['version_code'] = $params['version_code'] ?? '';
        $params['channel'] = $params['channel'] ?? '';
        $params['package'] = $params['package'] ?? '';
        // 如果非通话中送礼，则为0
        $params['call_id'] = intval($params['call_id'] ?? 0);
        // 主播相片索礼方案id
        $params['pid'] = intval($params['pid'] ?? 1);
        // 是否为背包送礼
        $params['is_backpack'] = intval($params['is_backpack'] ?? 0);
        $request->execute($params);
        $params['language'] = Context::get('language');
        $result = $this->giftService->sendGift($userInfo, $params);
        return $this->return($result);

    }

}